package com.ts.mapper.achievement;

import com.ts.entity.SoftwareCopyright;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SoftwareCopyrightMapper {
    /**
     * 新增软件著作权
     */
    @Insert("INSERT INTO ts_software_copyright (" +
            "software_name, software_type, version_number, copyright_registration_number, " +
            "developer_name, developer_rank, copyright_owner, development_completion_time, " +
            "registration_time, is_teacher, is_student, is_first_completion_unit, " +
            "achievement_source, subject_classification, sub_subject_classification, " +
            "remark, evidence_material, create_by, create_time, update_by, update_time, project_id" +
            ") VALUES (" +
            "#{softwareName}, #{softwareType}, #{versionNumber}, #{copyrightRegistrationNumber}, " +
            "#{developerName}, #{developerRank}, #{copyrightOwner}, #{developmentCompletionTime}, " +
            "#{registrationTime}, #{isTeacher}, #{isStudent}, #{isFirstCompletionUnit}, " +
            "#{achievementSource}, #{subjectClassification}, #{subSubjectClassification}, " +
            "#{remark}, #{evidenceMaterial}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{projectId}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(SoftwareCopyright softwareCopyright);

    /**
     * 根据ID查询
     */
    @Select("SELECT * FROM ts_software_copyright WHERE id = #{id} AND deleted = 0")
    SoftwareCopyright selectById(Long id);

    /**
     * 更新软件著作权
     */
    @Update("UPDATE ts_software_copyright SET " +
            "software_name = #{softwareName}, " +
            "software_type = #{softwareType}, " +
            "version_number = #{versionNumber}, " +
            "copyright_registration_number = #{copyrightRegistrationNumber}, " +
            "developer_name = #{developerName}, " +
            "developer_rank = #{developerRank}, " +
            "copyright_owner = #{copyrightOwner}, " +
            "development_completion_time = #{developmentCompletionTime}, " +
            "registration_time = #{registrationTime}, " +
            "is_teacher = #{isTeacher}, " +
            "is_student = #{isStudent}, " +
            "is_first_completion_unit = #{isFirstCompletionUnit}, " +
            "achievement_source = #{achievementSource}, " +
            "subject_classification = #{subjectClassification}, " +
            "sub_subject_classification = #{subSubjectClassification}, " +
            "remark = #{remark}, " +
            "evidence_material = #{evidenceMaterial}, " +
            "update_by = #{updateBy}, " +
            "update_time = #{updateTime}, " +
            "project_id = #{projectId} " +
            "WHERE id = #{id} AND deleted = 0")
    void update(SoftwareCopyright softwareCopyright);

    /**
     * 删除软件著作权（逻辑删除）
     */
    @Delete("UPDATE ts_software_copyright SET deleted = 1 WHERE id = #{id}")
    void deleteById(Long id);

    /**
     * 查询所有软件著作权
     */
    @Select("SELECT * FROM ts_software_copyright WHERE deleted = 0 ORDER BY create_time DESC")
    List<SoftwareCopyright> selectAll();

    /**
     * 根据软件名称查询
     */
    @Select("SELECT * FROM ts_software_copyright WHERE software_name LIKE CONCAT('%', #{softwareName}, '%') AND deleted = 0")
    List<SoftwareCopyright> selectBySoftwareName(String softwareName);

    /**
     * 根据著作权人查询
     */
    @Select("SELECT * FROM ts_software_copyright WHERE copyright_owner = #{copyrightOwner} AND deleted = 0")
    List<SoftwareCopyright> selectByCopyrightOwner(String copyrightOwner);
}